<?php
    include_once("../config.php");
    include_once(DAO_PATH . "/ProductDAO.php");
    include_once(OBJECT_PATH . "/Product.php");
    include_once(DAO_PATH . "/ComponentDAO.php");
    include_once(OBJECT_PATH . "/Component.php");

    $action = $_REQUEST['action'];

    if ($action == "getProduct")
    {
        $productId = $_REQUEST['id'];

        $dao = new ProductDAO();
        $product = $dao->getProduct($productId);
        $components = $product->getComponentIdList();

        header ("Content-Type:text/xml");
        echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
        echo "<product>";
        echo "<id>" . $product->getId() . "</id>";
        echo "<name>" . $product->getName() . "</name>";
        echo "<description>" . $product->getDescription() . "</description>";
        echo "<price>" . $product->getPrice() . "</price>";
        echo "<components>";
        for ($i = 0; $i < sizeof($components); $i++)
        {
            echo "<id>" . $components[$i] . "</id>";
        }
        echo "</components>";
        echo "</product>";
    }
?>
